<?php


namespace King\Service;


class PokerCompareService
{

    /**
     * @var PokerRuleService
     */
    public $prev;
    /**
     * @var PokerRuleService
     */
    public $current;

    public $compareStatus;

    public static $pokerSort = [
        '3' => 1,
        '4' => 2,
        '5' => 3,
        '6' => 4,
        '7' => 5,
        '8' => 6,
        '9' => 7,
        '10' => 8,
        'J' => 9,
        'Q' => 10,
        'K' => 11,
        'A' => 12,
        '2' => 13,
    ];

    public function __construct($prev, $current)
    {
        $this->prev = $prev;
        $this->current = $current;
        $this->make();
    }


    public function make()
    {
        if ($this->prev->len == $this->current->len && $this->prev->type == $this->current->type) {
            switch ($this->prev->type) {
                case 'singleCard':
                    $this->singleCard($this->prev->numList,$this->current->numList);
                    break;
                case 'pair':
                    $this->pair();
                    break;
                case 'leopard':
                    $this->leopard();
                    break;
                case 'bomb':
                    $this->bomb();
                    break;
                case 'straight':
                    $this->straight();
                    break;
            }
//            $this->kingBomb();
//            $this->kingBelt();
            //compare size
        } else {
            //compare type
            //['kingBomb','bomb']
        }
    }

    public function check(): bool
    {
        if (!$this->compareStatus) {
            throw new \Exception('outCard Compare Faild');
        }
        return $this->compareStatus;
    }

    public function singleCard($prevNumList,$currentNumList): bool
    {
        $prevSort = self::$pokerSort[(new \ArrayObject($prevNumList))->offsetGet(0)];
        $currentSort = self::$pokerSort[(new \ArrayObject($currentNumList))->offsetGet(0)];
        return $this->compareStatus = ($currentSort > $prevSort);
    }

    private function pair()
    {
        if (count($this->prev->valueCountList) > 1) {
            //multi pair compare

        } else {
            return $this->singleCard(array_unique($this->prev->numList), array_unique($this->current->numList));
        }
    }

    private function leopard()
    {
    }

    private function bomb()
    {

    }

    private function straight()
    {

    }

}